package com.example.demo.huawei;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/*
剩余银饰重量
 */
public class Main570 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            list.add(scanner.nextInt());
        }


        while (list.size() > 2) {
            list.sort(((o1, o2) -> o2 - o1));

            Integer z = list.get(0);

            Integer y = list.get(1);

            Integer x = list.get(2);

            if (x == y && y == z) {

            } else if (x == y && y != z) {
                list.add(z - y);
            } else if (y == z && x != y) {
                list.add(y - x);
            } else if (x != y && y != z) {
                int abs = Math.abs((z - y) - (y - x));
                if (abs != 0) {
                    list.add(abs);
                }
            }
            list.remove(x);
            list.remove(y);
            list.remove(z);
        }
        if (list.size() == 2) {
            System.out.println(list.get(0));
        } else if (list.size() == 1) {
            System.out.println(list.get(0));
        } else {
            System.out.println(0);
        }

    }
}
